<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/css/jquery.layout-latest.css}" rel="stylesheet" />

<body class="gray-bg">

	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="userInfo-from">
					<div class="select-list">
						<ul>
							<li>用户名：<input type="text" name="username" />
							</li>
							<li>姓名：<input type="text" name="name" />
							</li>
							<li>用户状态：<select name="state" id="state">
									<option value="" label="所有"/>
									<option value="1" label="在职"/>
									<option value="2" label="离职"/>
							</select>
							</li>
							<li>职位：<select name="position" id="position">
									<option value="">所有</option>
									<option value="1">管理员</option>
									<option value="2">理发师</option>
									<option value="3">收银员</option>
							</select>
							</li>
							<li><a class="btn btn-primary btn-rounded btn-sm"
								onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm"
								onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()"> <i
					class="fa fa-plus"></i> 添加
				</a> <a class="btn btn-primary btn-edit disabled"
					onclick="$.operate.edit()"> <i class="fa fa-edit"></i> 修改
				</a> <a class="btn btn-danger btn-del btn-del disabled"
					onclick="$.operate.removeAll()"> <i class="fa fa-remove"></i>
					删除
				</a>
				<!-- <a class="btn btn-warning" onclick="$.table.exportExcel()"> <i
					class="fa fa-download"></i> 导出
				</a> -->
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	<div th:include="include :: footer"></div>
	<script th:inline="javascript">
       
        $(function() {
            var options = {
           		method:"get",
                url:  "/userInfo/list",
                createUrl:  "/userInfo/add",
                updateUrl:  "/userInfo/edit/{id}",
                removeUrl:  "/userInfo/remove",                          	
				/* exportUrl: prefix + "/export",  */
                modalName: "职工管理",
				search: false,
		        
                columns: [{
		            checkbox: true
		        },
				{
					field : 'uid', 
					title : '序号',
					visible: false
				},
				{
					field : 'username', 
					title : '用户名',
					sortable: true
				},
				{
					field : 'name', 
					title : '姓名',
					sortable: true
				},
				 {
                    filed: 'state',
                    title: '在职情况',
                    formatter: function (value) {
						switch (value) {
							case 1:
								return '在职'
							case 2:
								return '离职'
						
						}
					}
                    
                },
				{
					field : 'position', 
					title : '职位' ,
					formatter: function (value) {
						switch (value) {
							case 1:
								return '管理员'
							case 2:
								return '理发师'
							case 3:
								return '收银员'
						}
					}
				},
				
				
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + '' + '" href="#" onclick="$.operate.edit(\'' + row.uid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + '' + '" href="#" onclick="$.operate.remove(\'' + row.uid + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-info btn-xs ' + '' + '" href="#" onclick="resetPwd(\'' + row.uid + '\')"><i class="fa fa-key"></i>重置</a>');
						return actions.join('');
		            }
		        }]
            };
            $('select#state').change(function(){
                
            	$.table.search();
                });
            $('select#position').change(function(){
                
            	$.table.search();
                });
            $.table.init(options);
        });

        function resetPwd(userId) {
            var url =  '/userInfo/resetPwd/' + userId;
            $.modal.open("重置密码", url, '800', '300');
        }

        function statusTools(row) {
            if (row.state == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.uid + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.uid + '\')"></i> ';
            }
        }

        /* 用户管理-停用 */
        function disable(userId) {
            $.modal.confirm("确认要停用用户吗？", function() {
                $.operate.post( "/userInfo/changeState", { "uid": userId, "state": 1 });
            })
        }

        /* 用户管理启用 */
        function enable(userId) {
            $.modal.confirm("确认要启用用户吗？", function() {
                $.operate.post("/userInfo/changeState", { "uid": userId, "state": 0 });
            })
        }
    </script>
</body>
</html>